from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-18 14:05:44.298448
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 18, Mar, 2021
Time: 14:05:48
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.9377
Nobs: 234.000 HQIC: -47.7308
Log likelihood: 2748.92 FPE: 1.09208e-21
AIC: -48.2667 Det(Omega_mle): 7.49359e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.458291 0.131659 3.481 0.000
L1.Burgenland 0.068728 0.066610 1.032 0.302
L1.Kärnten -0.207170 0.056406 -3.673 0.000
L1.Niederösterreich 0.141152 0.148869 0.948 0.343
L1.Oberösterreich 0.249120 0.134586 1.851 0.064
L1.Salzburg 0.210591 0.071972 2.926 0.003
L1.Steiermark 0.111930 0.096083 1.165 0.244
L1.Tirol 0.107854 0.064477 1.673 0.094
L1.Vorarlberg -0.001022 0.059332 -0.017 0.986
L1.Wien -0.125498 0.123106 -1.019 0.308
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.470047 0.156629 3.001 0.003
L1.Burgenland 0.017615 0.079243 0.222 0.824
L1.Kärnten 0.347137 0.067103 5.173 0.000
L1.Niederösterreich 0.090319 0.177103 0.510 0.610
L1.Oberösterreich -0.104856 0.160111 -0.655 0.513
L1.Salzburg 0.188827 0.085622 2.205 0.027
L1.Steiermark 0.193071 0.114306 1.689 0.091
L1.Tirol 0.133955 0.076706 1.746 0.081
L1.Vorarlberg 0.156868 0.070584 2.222 0.026
L1.Wien -0.479921 0.146454 -3.277 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.307419 0.061483 5.000 0.000
L1.Burgenland 0.093925 0.031106 3.020 0.003
L1.Kärnten -0.018665 0.026341 -0.709 0.479
L1.Niederösterreich 0.064922 0.069520 0.934 0.350
L1.Oberösterreich 0.296365 0.062850 4.715 0.000
L1.Salzburg 0.012761 0.033610 0.380 0.704
L1.Steiermark -0.007939 0.044869 -0.177 0.860
L1.Tirol 0.070215 0.030110 2.332 0.020
L1.Vorarlberg 0.102330 0.027707 3.693 0.000
L1.Wien 0.084966 0.057488 1.478 0.139
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.220364 0.065596 3.359 0.001
L1.Burgenland -0.000531 0.033187 -0.016 0.987
L1.Kärnten 0.015177 0.028103 0.540 0.589
L1.Niederösterreich 0.033880 0.074170 0.457 0.648
L1.Oberösterreich 0.398805 0.067054 5.947 0.000
L1.Salzburg 0.081829 0.035858 2.282 0.022
L1.Steiermark 0.174235 0.047871 3.640 0.000
L1.Tirol 0.042056 0.032124 1.309 0.190
L1.Vorarlberg 0.080522 0.029560 2.724 0.006
L1.Wien -0.046081 0.061334 -0.751 0.452
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.514494 0.129752 3.965 0.000
L1.Burgenland 0.064359 0.065645 0.980 0.327
L1.Kärnten 0.004714 0.055588 0.085 0.932
L1.Niederösterreich -0.029718 0.146712 -0.203 0.839
L1.Oberösterreich 0.147407 0.132636 1.111 0.266
L1.Salzburg 0.069474 0.070930 0.979 0.327
L1.Steiermark 0.095630 0.094691 1.010 0.313
L1.Tirol 0.220952 0.063543 3.477 0.001
L1.Vorarlberg 0.028332 0.058472 0.485 0.628
L1.Wien -0.104964 0.121322 -0.865 0.387
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185294 0.095855 1.933 0.053
L1.Burgenland -0.021048 0.048495 -0.434 0.664
L1.Kärnten -0.013070 0.041066 -0.318 0.750
L1.Niederösterreich 0.006491 0.108384 0.060 0.952
L1.Oberösterreich 0.411607 0.097986 4.201 0.000
L1.Salzburg 0.007466 0.052400 0.142 0.887
L1.Steiermark -0.015339 0.069954 -0.219 0.826
L1.Tirol 0.168402 0.046943 3.587 0.000
L1.Vorarlberg 0.050853 0.043196 1.177 0.239
L1.Wien 0.225434 0.089627 2.515 0.012
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.239218 0.123601 1.935 0.053
L1.Burgenland 0.034722 0.062533 0.555 0.579
L1.Kärnten -0.043925 0.052953 -0.829 0.407
L1.Niederösterreich -0.039244 0.139758 -0.281 0.779
L1.Oberösterreich -0.051189 0.126349 -0.405 0.685
L1.Salzburg 0.072772 0.067567 1.077 0.281
L1.Steiermark 0.373666 0.090203 4.143 0.000
L1.Tirol 0.446229 0.060531 7.372 0.000
L1.Vorarlberg 0.162507 0.055700 2.918 0.004
L1.Wien -0.190683 0.115571 -1.650 0.099
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124163 0.145333 0.854 0.393
L1.Burgenland 0.030528 0.073528 0.415 0.678
L1.Kärnten -0.059207 0.062264 -0.951 0.342
L1.Niederösterreich 0.206566 0.164330 1.257 0.209
L1.Oberösterreich -0.029208 0.148564 -0.197 0.844
L1.Salzburg 0.246148 0.079447 3.098 0.002
L1.Steiermark 0.142201 0.106062 1.341 0.180
L1.Tirol 0.040369 0.071174 0.567 0.571
L1.Vorarlberg 0.074339 0.065493 1.135 0.256
L1.Wien 0.225079 0.135891 1.656 0.098
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.576800 0.079005 7.301 0.000
L1.Burgenland -0.031789 0.039971 -0.795 0.426
L1.Kärnten -0.015808 0.033848 -0.467 0.640
L1.Niederösterreich 0.018454 0.089333 0.207 0.836
L1.Oberösterreich 0.312948 0.080762 3.875 0.000
L1.Salzburg 0.011300 0.043189 0.262 0.794
L1.Steiermark -0.011836 0.057657 -0.205 0.837
L1.Tirol 0.079227 0.038691 2.048 0.041
L1.Vorarlberg 0.115522 0.035603 3.245 0.001
L1.Wien -0.046684 0.073873 -0.632 0.527
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.133142 0.044468 0.190588 0.237265 0.065377 0.126532 -0.030277 0.161972
Kärnten 0.133142 1.000000 0.005196 0.195533 0.167406 -0.104972 0.143845 0.016223 0.304504
Niederösterreich 0.044468 0.005196 1.000000 0.267851 0.060019 0.266973 0.148853 0.050121 0.312316
Oberösterreich 0.190588 0.195533 0.267851 1.000000 0.290958 0.262448 0.092849 0.071438 0.138529
Salzburg 0.237265 0.167406 0.060019 0.290958 1.000000 0.117328 0.067061 0.086737 -0.002288
Steiermark 0.065377 -0.104972 0.266973 0.262448 0.117328 1.000000 0.116986 0.118349 -0.124296
Tirol 0.126532 0.143845 0.148853 0.092849 0.067061 0.116986 1.000000 0.164188 0.152260
Vorarlberg -0.030277 0.016223 0.050121 0.071438 0.086737 0.118349 0.164188 1.000000 0.019851
Wien 0.161972 0.304504 0.312316 0.138529 -0.002288 -0.124296 0.152260 0.019851 1.000000